﻿package frEngine.shader.filters.fragmentFilters.extra
{
    import __AS3__.vec.*;
    import baseEngine.system.*;
    import flash.geom.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.filters.fragmentFilters.*;

    public class XRayFilter extends FragmentFilter
    {
        public var rimColor:Vector.<Number>;
        public var cameraPos:Vector.<Number>;

        public function XRayFilter(param1:Array = null)
        {
            this.rimColor = this.Vector.<Number>([0.2, 0.3, 0.9, 1]);
            this.cameraPos = this.Vector.<Number>([0, 0, 0, 1]);
            super(param1);
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{CamPos}", false).value = Global3D.scene.cpos;
            param1.getParamByName("{RimColor}", false).value = this.rimColor;
            return;
        }// end function

        override public function get programeId() : String
        {
            return "XrayFilter";
        }// end function

        override public function clone() : FilterBase
        {
            return this;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:Array = [new ToBuilderInfo("vf1", "{V_GloblePos}", false, 1)];
            param1.toBuild("", _loc_3);
            return "";
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("fc1", "{CamPos}", false, 1, Global3D.scene.cpos));
            _loc_3.push(new ToBuilderInfo("fc2", "{RimColor}", false, 1, this.rimColor));
            _loc_3.push(new ToBuilderInfo("fm0", FilterName.global, true, 4));
            var _loc_4:String = "";
            _loc_4 = _loc_4 + ("sub ft1, {CamPos}, {V_GloblePos} \n" + "nrm ft1.xyz, ft1 \n" + "m33 ft2.xyz,{vnormal},fm0 \n" + "dp3 ft3.x, ft1.xyz, ft2.xyz \n" + "sat ft3.x, ft3.x  \n" + "sub ft3.x, {fcConst1}.z, ft3.x \n" + "mul {output}, ft3.x,  {RimColor} \n");
            return param1.toBuild(_loc_4, _loc_3);
        }// end function

        public function updateCameraPos() : void
        {
            var _loc_1:* = Global3D.camera.pos;
            this.cameraPos[0] = _loc_1.x;
            this.cameraPos[1] = _loc_1.y;
            this.cameraPos[2] = _loc_1.z;
            this.cameraPos[3] = 1;
            return;
        }// end function

    }
}
